#include<iostream>
using namespace std;
int x[100];
int Place(int k);
int Queen(int n)
{
    int count = 0;
    for (int i = 1; i <= n; i++)
        x[i] = 0;
    int k = 1;
    while (k >= 1)
    {
        x[k] = x[k] + 1;
        while (x[k] <= n && (!Place(k)))
            x[k] = x[k] + 1;
        if (k == n && x[k] <= n)
        {
            count++;
            for (int i = 1; i <= k; i++)
                cout << x[i] << " ";
            cout << endl;
        }
        else if (k < n && x[k] <= n)
            k = k + 1;
        else
        {
            x[k] = 0;
            k = k - 1;
        }
    }
    return count;
}
int Place(int k)
{
    for (int i = 1; i < k; i++)
        if (x[i] == x[k] || abs(i - k) == abs(x[i] - x[k]))
            return false;
    return true;
}
int main()
{
    int n = 4;
    int result = Queen(n);
    std::cout << "scheme number is:" << result << std::endl;
    return 0;
}